We'll focus on maps and cartrographic visualization. In this lab, you will practice:
After building these charts, you will make a website with these charts using streamlit.
import pandas as pd
import altair as alt
from vega_datasets import data
alt.data_transformers.disable_max_rows()
df = pd.read_csv('https://raw.githubusercontent.com/pratik-mangtani/si649-hw/main/airports.csv')
url = "https://raw.githubusercontent.com/pratik-mangtani/si649-hw/main/small-airports.json"
df.head()
| id | ident | type | name | latitude_deg | longitude_deg | elevation_ft | continent | iso_country | iso_region | municipality | scheduled_service | gps_code | iata_code | local_code | home_link | wikipedia_link | keywords | |
|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|
| 0 | 6523 | 00A | heliport | Total Rf Heliport | 40.070801 | -74.933601 | 11.0 | NaN | US | US-PA | Bensalem | no | 00A | NaN | 00A | NaN | NaN | NaN |
| 1 | 323361 | 00AA | small_airport | Aero B Ranch Airport | 38.704022 | -101.473911 | 3435.0 | NaN | US | US-KS | Leoti | no | 00AA | NaN | 00AA | NaN | NaN | NaN |
| 2 | 6524 | 00AK | small_airport | Lowell Field | 59.947733 | -151.692524 | 450.0 | NaN | US | US-AK | Anchor Point | no | 00AK | NaN | 00AK | NaN | NaN | NaN |
| 3 | 6525 | 00AL | small_airport | Epps Airpark | 34.864799 | -86.770302 | 820.0 | NaN | US | US-AL | Harvest | no | 00AL | NaN | 00AL | NaN | NaN | NaN |
| 4 | 506791 | 00AN | small_airport | Katmai Lodge Airport | 59.093287 | -156.456699 | 80.0 | NaN | US | US-AK | King Salmon | no | 00AN | NaN | 00AN | NaN | NaN | NaN |
Description of the visualization:
We want to visualize the density of small airports in the world. Each small airport is represented by a dot. The visualization has two layers:
Hint:
df1 = df[df["type"] == "small_airport"]
# TODO: Vis 1
url = "https://raw.githubusercontent.com/deldersveld/topojson/master/world-continents.json"
source = alt.topo_feature(url, "continent")
base = alt.Chart(source).mark_geoshape(
fill='lightgray',
stroke='white'
).project('mercator').properties(
width=800,
height=600
)
points = alt.Chart(df1).mark_circle().encode(
longitude='longitude_deg:Q',
latitude='latitude_deg:Q',
size=alt.value(10),
tooltip='name:N',
color=alt.value('red')
)
(base + points).properties(title='Small airports in the world').configure_title(fontSize=20)